package controllers {
  import com.axon.mvc.helpers.AxVerbs;
  import com.axon.mvc.patterns.command.AxSimpleCommand;
  import com.axon.mvc.patterns.facade.AxFacade;

  import helpers.LoginCredentials;

  import models.proxies.AnaliseProxy;
  import models.proxies.AtividadeProxy;
  import models.proxies.DocumentoApresentadoProxy;
  import models.proxies.ExigenciaProxy;
  import models.proxies.FotoProxy;
  import models.proxies.PleitoProxy;
  import models.proxies.ProdutoProxy;
  import models.proxies.ProdutoServicoProxy;
  import models.proxies.SessionProxy;
  import models.proxies.UserProxy;
  import models.proxies.VistoriaProxy;

  import views.mediators.AppMediator;
  import views.mediators.LoungeMediator;
  import views.mediators.LoungePopUpLoginMediator;
  import views.mediators.LoungeStatusTopRightMediator;

  public class AppCommand extends AxSimpleCommand {
    //////////////////////////////////////////////////////////////////////////////////////////////////////

    public function execStartup(sender:Object, body:Object, extraInfo:Object):void {
      var app:Pleitos = (facade as AppFacade).app;

      // RESGISTER PROXIES 

      facade.registerProxy(new SessionProxy());
      facade.registerProxy(new UserProxy());
      facade.registerProxy(new PleitoProxy());
      facade.registerProxy(new AnaliseProxy());
      facade.registerProxy(new VistoriaProxy());
      facade.registerProxy(new FotoProxy());
      facade.registerProxy(new ExigenciaProxy());
      facade.registerProxy(new AtividadeProxy());
      facade.registerProxy(new ProdutoProxy());
      facade.registerProxy(new ProdutoServicoProxy());
      facade.registerProxy(new DocumentoApresentadoProxy());

      // RESGISTER MEDIATORS

      facade.registerMediator(new AppMediator(app));
      facade.registerMediator(new LoungeMediator(app.loungeView));
      facade.registerMediator(new LoungeStatusTopRightMediator(app.loungeStatusTopRightView));

      // DISPATCH LOGIN BROADCAST MESSAGE

      (facade as AppFacade).broadcastMessage((facade as AxFacade).getMediator(LoungeMediator), AxVerbs.LOGIN_POPUP);
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////

    public function execLoginPopUp(sender:Object, body:Object, extraInfo:Object):void {
      (facade as AppFacade).regMediator(new LoungePopUpLoginMediator(
        (facade as AppFacade).loungeMediator.displayObject));
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////

    public function execLogin(sender:Object, body:Object, extraInfo:Object):void {
      (facade as AppFacade).sessionProxy.login(body as LoginCredentials);
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////

    public function execLogout(sender:Object, body:Object, extraInfo:Object):void {
      (facade as AppFacade).sessionProxy.logout();
    }

  }
}